From 0f27ca80fbdb3366e047def628123d3cc8ca051c Mon Sep 17 00:00:00 2001
From: Ilion Beyst <ilion.beyst@gmail.com>
Date: Thu, 30 Dec 2021 23:41:47 +0100
Subject: prototype code upload

---
 web/pw-server/src/routes/bots/[bot_id].svelte | 30 ++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

(limited to 'web/pw-server/src/routes/bots/[bot_id].svelte')

diff --git a/web/pw-server/src/routes/bots/[bot_id].svelte b/web/pw-server/src/routes/bots/[bot_id].svelte
index 90fd78d..1d7994d 100644
--- a/web/pw-server/src/routes/bots/[bot_id].svelte
+++ b/web/pw-server/src/routes/bots/[bot_id].svelte
@@ -6,7 +6,7 @@
     const res = await fetch(`/api/bots/${page.params["bot_id"]}`, {
       headers: {
         "Content-Type": "application/json",
-        Authorization: `Bearer ${token}`,
+        "Authorization": `Bearer ${token}`,
       },
     });
 
@@ -27,8 +27,36 @@
 
 <script lang="ts">
   export let bot: object;
+
+  let files;
+
+  async function submitCode() {
+    console.log("click");
+    const token = get_session_token();
+
+    const formData = new FormData();
+    formData.append("File", files[0]);
+
+    const res = await fetch(`/api/bots/${bot["id"]}/upload`, {
+      method: "POST",
+      headers: {
+        // the content type header will be set by the browser
+        "Authorization": `Bearer ${token}`,
+      },
+      body: formData,
+    });
+
+    console.log(res.statusText);
+  }
 </script>
 
 <div>
   {bot["name"]}
 </div>
+
+
+<div>Upload code</div>
+<form on:submit|preventDefault={submitCode}>
+  <input type="file" bind:files/>
+  <button type="submit">Submit</button>
+</form>
\ No newline at end of file
-- 
cgit v1.2.3

